package com.ybkj.o2o.zhuanche.controller;

import com.ybkj.o2o.zhuanche.common.DataGrid;
import com.ybkj.o2o.zhuanche.controller.v4.ErrorConstantV4;
import com.ybkj.o2o.zhuanche.controller.v4.ResultTransport;
import com.ybkj.o2o.zhuanche.entity.PassengerComplaints;
import com.ybkj.o2o.zhuanche.manager.PassengerComplaintsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * Created by Administrator on 2017/3/8.
 */
@Controller
@RequestMapping("api/passengercomplaints")
public class PassengerComplaintsRes {

  @Autowired
  private PassengerComplaintsManager passengerComplaintsManager;


  @RequestMapping("create")
  @ResponseBody
  public ResultTransport create(
      @RequestParam("complaintTime")Long  complaintTime,
      @RequestParam("detail") String  detail,
      @RequestParam("orderId") Long   orderId,
      @RequestParam(required = false,value="result")String  result,
      @RequestParam("appKey")String appKey){
    ResultTransport response = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
    try{
      PassengerComplaints pc = new PassengerComplaints();
      pc.setComplaintTime(new Date(complaintTime));
      pc.setDetail(detail);
      pc.setResult(result);
      pc.setOrderId(orderId);
      pc.setAppKey(appKey);
      pc = passengerComplaintsManager.create(pc);
      response.setData(pc);
    }catch (Exception e){
      e.printStackTrace();
      response = ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
    return response;
  }


  @RequestMapping("findByPage")
  @ResponseBody
  public ResultTransport findByPage(
      @RequestParam("orderId")Long orderId,
      @RequestParam(required = false,value="page")Integer  page,
      @RequestParam(required = false,value="rows")Integer rows,
      @RequestParam("appKey")String appKey){
    ResultTransport response = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
    try{
      DataGrid<PassengerComplaints> pcs = passengerComplaintsManager.findByPage(orderId,appKey,page,rows);
      response.setData(pcs);
    }catch (Exception e){
      e.printStackTrace();
      response = ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
    return response;
  }
  @RequestMapping("delete")
  @ResponseBody
  public ResultTransport delete(
      @RequestParam("pcId")Long pcId,
      @RequestParam("appKey")String appKey){
    ResultTransport response = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
    try{
      PassengerComplaints pc = passengerComplaintsManager.deleteById(pcId,appKey);
      response.setData(pc);
    }catch (Exception e){
      e.printStackTrace();
      response = ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
    }
    return response;
  }






}
